package config

import (
	"flag"
	"fmt"
	"strconv"
	"strings"
	"token-for-token/config/setting"
	"token-for-token/global"
)

func SetupParams() {
	//global.BlockChainConfig = &setting.BlockChainConfig{
	//	RpcUrl: "https://bsc-dataseed.binance.org",
	//	Name:   "BSC",
	//	Id:     97,
	//	//Type:   "TOKEN-FOR-TOKEN",
	//}

	rpc := flag.String("rpc", "", "rpc")
	chainName := flag.String("name", "", "链名称")
	chainId := flag.String("id", "", "链ID")
	diffNum := flag.String("diff", "", "区块间隔")
	//types := flag.String("type", "", "类型")
	flag.Parse()

	if *rpc == "" || *chainName == "" || *chainId == "" {
		fmt.Println("请提供环境变量值")
		return
	} else {
		// 字符串转int64
		id, err := strconv.ParseInt(*chainId, 10, 64)
		if err != nil {
			fmt.Printf("id不是正整数：%v", err)
			return
		}
		diff, err := strconv.ParseInt(*diffNum, 10, 64)
		if err != nil {
			fmt.Printf("diff不是正整数：%v", err)
			return
		}

		global.BlockChainConfig = &setting.BlockChainConfig{
			RpcUrl: *rpc,
			Name:   strings.ToUpper(*chainName),
			Id:     id,
			Diff:   diff,
		}
	}
}
